import { IRouteItem } from "..";

export class RouteManager {
    static Current: RouteManager = new RouteManager();
    private routes: Map<IRouteItem, Function | Function[]> = new Map();

    AddRoute(routeItem: IRouteItem, controller: Function | Function[]) {
        this.routes.set(routeItem, controller);
    }

    get Routes() { return this.routes; }

    private ctrlList: { ctrlName: string; ctrl }[] = [];
    AddController(name: string, ctrl) {
        let c = this.ctrlList.find(x => x.ctrlName == name);
        if (c) return c.ctrl;
        else {
            c = { ctrlName: name, ctrl: ctrl };
            this.ctrlList.push(c);
            return c.ctrl;
        }
    }

    Destory() {
        this.ctrlList = null;
        this.routes = null;
    }
}
